package com.linln.admin.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.business.domain.Attendance;
import com.linln.modules.business.service.impl.AttendanceServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 考勤打卡
 * @author Administrator
 */
@Controller
@RequestMapping("/business/punch")
public class PunchController {


    @Autowired
    private AttendanceServiceImpl attendanceService;

    /**
     * 个人打卡记录页
     */
    @GetMapping("/index")
    @RequiresPermissions("business:punch:index")
    public String index(Model model, Attendance attendance) {

        IPage<Attendance> page = attendanceService.getMyAttendances(attendance);
        model.addAttribute("list",page.getRecords());
        model.addAttribute("page",page);
        return "/business/punch/index";
    }

    /**
     * 考勤打卡
     * @param type
     * @return
     */
    @GetMapping("/record/{type}")
    @ResponseBody
    public ResultVo punch(@PathVariable("type") Integer type){
        boolean res = attendanceService.punch(type);
        if(res){
            return ResultVoUtil.success("打卡成功！");
        }else{
            return ResultVoUtil.error("打卡失败！");
        }
    }

}
